/** 
 * 编制课程
*/
<template>
    <vp-dialog ref="dialogRef">    
        <template #title>
            <vp-label v-if="type == 'add'" zh="新增课程" en="Add Course" align="left"/>
            <vp-label v-if="type == 'edit'" zh="修改课程" en="Edit Course" align="left"/>
            <vp-label v-if="type == 'revision'" zh="修订课程" en="Revise Course" align="left"/>
        </template>
        <Course ref="courseRef" :id="id" :type="type"></Course>
        <template #footer>
            <vp-btn-save v-if="type != 'revision'" :loading="saveLoading"  @click="handleSave(10)"></vp-btn-save>
            <vp-btn-submit :loading="saveLoading"  @click="handleSave(20)"></vp-btn-submit>
        </template>
    </vp-dialog>
</template>

<script setup lang="ts" name="EditCourse">
import { defineAsyncComponent, defineExpose, ref } from 'vue'
import validateUtils from '/@/utils/validateUtils';
import request from '/@/utils/request';

const Course = defineAsyncComponent(() => import('./Course.vue'));
const ProcessHandle = defineAsyncComponent(() => import('/@/components/vp/workflow/VpProcessHandle.vue'));
const UserDialog = defineAsyncComponent(() => import('/@/components/vp/user/VpUserDialog.vue'));

const emits = defineEmits<{
    (e: 'formSubmited'): void
}>()

const dialogRef = ref();
const type = ref('add');
const id = ref('');
const saveLoading = ref(false);

const initExtFormData = () =>{
    
}

const courseRef = ref();

const handleOpen = (_type: string, _id: string)=>{
    id.value = _id;
    type.value = _type;
    initExtFormData();
    dialogRef.value.handleOpen();
}
const handleSave = (zt : number) =>{
    saveLoading.value = true;
    courseRef.value.getData(zt).then((data: any) =>{
        request.post("/training/course/" + type.value, {
            ...data,
            zt: zt,
        }).then(() => {
            emits('formSubmited')
            dialogRef.value.handleClose();
        })
        .catch(() => {})
        .finally(() => {
            saveLoading.value = false;
        });
    }).catch(()=>{saveLoading.value = false;});    
}

defineExpose({
    handleOpen
})
</script>
<style scoped lang="scss">

</style>
